package com.db.onlinedb.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * mysql连接池
 */
public class MysqlConnectionPool {
    private static List<Conn> pool = new ArrayList<>();

    /**
     * 私有构造方法
     */
    private MysqlConnectionPool() {
    }

    /**
     * 全局访问点，获取Conn
     *
     * @return Conn
     */
    public static Conn getConn() {
        if (pool.size() == 0) {
            return new Conn();
        }
        Conn conn = pool.get(0);
        pool.remove(0);
        return conn;
    }

    /**
     * 全局回收点，回收Conn
     *
     * @param conn 连接
     */
    public static void recovery(Conn conn) {
        pool.add(conn);
    }
}
